package org.goobs.csp;



import java.util.ArrayList;
import java.util.Collection;

public abstract class UnaryConstraint <Domain> implements IConstraint{
	
	protected CSPVariable <Domain> var;
	
	public UnaryConstraint(CSPVariable <Domain> var){
		this.var = var;
	}
	
	@SuppressWarnings("unchecked")
	public abstract boolean isSatisfied();
	
	
	@SuppressWarnings("unchecked")
	public Collection <ICSPArc> generateArcs(CSP csp){
		ICSPArc arc = new ICSPArc() {
			@Override
			public boolean isOK() {
				if(var.getValue() == null){
					return true;
				}
				return isSatisfied();
			}
			@Override
			public CSPVariable getTail() {
				return var;
			}
			@Override
			public CSPVariable getHead() {
				return var;
			}
		};
		
		Collection rtn = new ArrayList <ICSPArc>();
		rtn.add(arc);
		
		return rtn;
	}
	
}
